package net.googlecode.demenkov.utils;

import java.util.Random;

/**
 * Class that generates random char-sequence as person's code for confirm registration
 *
 * @author Demenkov Yura
 */
public class VerificateCodeGenerator {
    Random rand = new Random();
    String symbols = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890_-";
    int len = 50;


    /**
     * generates random char-sequence as person's code for confirm registration
     *
     * @return random char-sequence with length=len
     */
    public String generateCode() {
        String code = "";
        StringBuilder codebuilder = new StringBuilder(code);
        for (int i = 0; i < len; i++) {
            codebuilder.append(symbols.charAt(rand.nextInt(symbols.length() - 1)));
        }
        return codebuilder.toString();
    }

}
